package mq.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.jms.Queue;
import javax.jms.Topic;

@Controller
public class DemoController {
    @Autowired
    @Qualifier("bootQueue")
    private Queue bootQueue;

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @GetMapping("/test")
    @ResponseBody
    public String testSendMessage(){
        // 发送消息到消息队列
        jmsMessagingTemplate.convertAndSend(bootQueue,"spring boot 测试消息...");
        return "ok";
    }

    @Resource
    private Topic topicQueue;

    @GetMapping("/test2")
    @ResponseBody
    public String testSendMessage2(){
        // 发送消息到消息队列
        jmsMessagingTemplate.convertAndSend(bootQueue,"spring boot 测试消息...");
        return "ok";
    }
}
